/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.zbxsoft.utr.service.plugins  
 */
package com.apache.bid.service.plugins;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.bid.common.BidCommonUtil;
import com.apache.bid.common.Constant;
import com.apache.bid.common.cache.BidCacheFactory;
import com.apache.bid.common.cache.BidCacheManager;
import com.apache.bid.common.vo.BidItemCacheVo;
import com.apache.bid.manager.BidItemManager;
import com.apache.cache.util.Validator;
import com.apache.rpc.client.RpcProtoclClient;

/**
 * description:  暂停item，
 * 输入：ParamsVo（要暂停的itemId）
 * 输出：T/F
 * 业务：控制标的的状态改为3
 * @author xhe 创建时间：2016-03-21  
 * 
 */
public class UnityStopItemPluginImpl implements PluginConnector {
	private Logger log = Logger.getLogger(getClass());

	@Autowired
	private BidItemManager bidItemManager;

	public Object execute(ParamsVo param) throws Exception {
		ResultEntity ret = new ResultEntity();
		ret.setResult("true");
		if (Constant.getInstance().ifWriteDatabase()) {
			String itemId = param.getInfoId();
			log.info("暂停标的：" + itemId);
			if (Validator.isNull(itemId)) {
				ret.setMessage("操作失败（itemId不能为空）");
				ret.setEntity("false");
				return ret;
			}
			BidItemCacheVo itemVo = null;
			BidCacheManager cache = BidCacheFactory.getInstance().getCacheManager("item");
			if (cache.checkCacheObject(cache.item_prefix + itemId)) {
				itemVo = (BidItemCacheVo) cache.getCacheCloneByKey(cache.item_prefix + itemId);
			} else {
				param.setMethodKey("ByIdVo");
				itemVo = (BidItemCacheVo) bidItemManager.getInfoById(param);
			}
			UnityItemPluginHelper.getInstance().pauseItem(itemVo, true);
			ret.setMessage("操作成功");
			ret.setEntity("true");
		} else {
			param.setParams("infoId", param.getInfoId());
			ret = RpcProtoclClient.getInstance().doService("wbdCacheService", "stopItem", param.getParams(),
					BidCommonUtil.getInstance().getInterfaceRegister("", ""));
			log.info("result=" + ret.getResult() + ";msg=" + ret.getMessage());
		}
		return ret;
	}

	public void setBidItemManager(BidItemManager bidItemManager) {
		this.bidItemManager = bidItemManager;
	}

}
